package com.mrx.java8.Date;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.*;

/**
 * 会有线程安全问题
 */
public class TestSimpleDateFormat {

    public static void main(String[] args) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

        ExecutorService pool = Executors.newFixedThreadPool(10);
        Callable<Date> task = () -> sdf.parse("2018-12-02");
        List<Future<Date>> results = new ArrayList<>();
        for(int i=0;i<10;i++){
            results.add(pool.submit(task));
        }

        for(Future<Date> future : results){
            try {
                System.out.println(future.get());
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (ExecutionException e) {
                e.printStackTrace();
            }
        }


    }
}
